<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" >
      <el-form-item label="组织" prop="orgId">
        <el-select v-model="queryParams.orgId" size="small" clearable placeholder="请选择组织">
          <el-option v-for="item in orgs" :label="item.name" :value="item.id" :key="item.id"/>
        </el-select>
      </el-form-item>
      <el-form-item label="业务日期" prop="biztime" label-width="100px">
        <el-date-picker v-model="queryParams.startBiztime" type="date" value-format="yyyy-MM-dd" size="mini" placeholder="请选择业务日期" clearable style="width: 191px"/> -
        <el-date-picker v-model="queryParams.endBiztime" type="date" value-format="yyyy-MM-dd" size="mini" placeholder="请选择结束日期" clearable style="width: 191px;"/>
      </el-form-item>
      <el-form-item label-width="100px">
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
<!--        <el-button @click="test1" :disabled="csDisabled">测试</el-button>-->
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="warning" icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="foodconsumList" >
      <el-table-column label="店铺" align="center" prop="mtOrgname" />
      <el-table-column label="ERP组织" align="center" prop="orgName" width="180"/>
      <el-table-column label="业务日期" align="center" prop="biztime"  width="140">
        <template slot-scope="scope">
          <span>{{parseTime(scope.row.biztime)}}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单日期范围" align="center" prop="orderstarttimegte" width="300">
        <template slot-scope="scope">
          <span v-if="scope.row.orderstarttimegte">{{parseTime(scope.row.orderstarttimegte)}} - {{parseTime(scope.row.orderendtimelte)}}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status" width="80" :formatter="foodConSumStat"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="80">
        <template slot-scope="scope">
          <el-button icon="el-icon-info" type="text" size="mini" @click="viewIt(scope.row.id)">详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listFoodconsum,exportFoodconsum } from "@/api/mt/foodconsum";
import {findOrganizationList} from '@/api/public'

export default {
  name: "mtFoodconsum",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 美团菜品消耗单主表格数据
      foodconsumList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        mtOrgid: null,
        mtRootorgid: null,
        orgId: null,
        orgName: null,
        mtWhCode: null,
        foodconsumptionsn: null,
        code: null,
        biztime: null,
        mtStatus: null,
        oncelackfoodbom: null,
        oncelackwarehouse: null,
        orderstarttimegte: null,
        orderendtimelte: null,
        version: null,
        strguid: null,
        departmentguid: null,
        status: null,
        startBiztime:null,
        endBiztime:null,
      },
      //菜品消耗单详情列表
      foodConSumItemList:[],
      orgs:[],
      foodConSumStatus:[],
      // 表单参数
      form: {},
      // csDisabled:false,
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getOrgs();
    this.getDicts("mt_foodConsum_status").then(response=>{
      this.foodConSumStatus=response.data;
    })
  },
  methods: {
    // test1(){
    //   this.csDisabled=true;
    //   setTimeout(()=>{
    //     this.csDisabled=false;
    //       console.log("1111")
    //   },2000
    //   )
    // },
    foodConSumStat(row,column){
      return this.selectDictLabel(this.foodConSumStatus,row.status);
    },
    getOrgs(){
      findOrganizationList().then(response=>{
        this.orgs=response.data;
      })
    },
    viewIt(id){
      this.$router.push({path:"/mt/mtFoodconsumItem",query:{mtFoodconsumid:id}})
    },
    /** 查询美团菜品消耗单主列表 */
    getList() {
      this.loading = true;
      listFoodconsum(this.queryParams).then(response => {
        this.foodconsumList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        mtOrgid: null,
        mtRootorgid: null,
        orgId: null,
        orgName: null,
        mtWhCode: null,
        foodconsumptionsn: null,
        code: null,
        biztime: null,
        mtStatus: 0,
        oncelackfoodbom: null,
        oncelackwarehouse: null,
        orderstarttimegte: null,
        orderendtimelte: null,
        version: null,
        strguid: null,
        departmentguid: null,
        status: 0,
        createTime: null,
        createBy: null,
        updateTime: null,
        updateBy: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有美团菜品消耗单主数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportFoodconsum(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
